import { createSlice } from "@reduxjs/toolkit"
import {getCookie, get__token} from '@Utils/getPageDecrypt'
export interface jinritemaiDecrypt {
    msToken: string,
    __token: string,
    userInfo: object,
    inInit: boolean
}

// 列表获取 后期异步获取数据 修改缓存
const jinritemaiDecrypt = createSlice({
    name: "jinritemaiDecrypt",
    initialState: {
        msToken: '',
        __token: '',
        userInfo: {},
        inInit: false
    },
    reducers: {
        setToken: (state) => {
            state.msToken = getCookie('msToken') || localStorage.getItem('xmst') || ''
            console.log('state.msToken', state.msToken)
            const getuserinfo = get__token()
            state.__token = getuserinfo.__token
            state.userInfo = getuserinfo.userInfo
        },
        setIsInit: (state, action: {payload: boolean}) => {
            state.inInit = action.payload
        }
    }
})

export const { setToken, setIsInit } = jinritemaiDecrypt.actions

export default jinritemaiDecrypt.reducer